package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.CurVideo;
import com.macro.mall.portal.service.CurVideoService;
import com.macro.mall.portal.service.CurVideoStatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * CurVideo的路由接口服务
 * 
 * @author 
 *
 */
@Slf4j
@RestController
@RequestMapping("curVideo")
@Api(tags = "CurVideoController", description = "课程视频(cur_course_base）")
public class CurVideoController {

	/** CurVideoService服务 */
	@Autowired
	private CurVideoService curVideoService;

	@Autowired
	private CurVideoStatService curVideoStatService;

    @ApiOperation("查询课程视频")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<CurVideo>> list(@RequestParam(value = "id", required = false) Long id,
                                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                   @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {

        List<CurVideo> bycondition = curVideoService.findByCourseId(id, pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(bycondition));
    }

    @ApiOperation("课程视频观看数")
    @RequestMapping(value = "/addNum", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult addNum(@RequestParam(value = "id", required = false) Long id) {

        curVideoStatService.addNum(id);
        return CommonResult.success(null);
    }




}
